<%@ page language="java" pageEncoding="UTF-8" import="com.chinapost.util.AuthUtil"%>
<%@ taglib prefix="my" uri="/WEB-INF/tlds/permission.tld" %>
<%
	AuthUtil authUtil = new AuthUtil(session);
%>
<script type="text/javascript">
	var jfsz_datagrid;
	$(function() {
		jfsz_datagrid = $('#jfsz_manager_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/jfszAction!datagrid.action',
			title:'积分规则列表',			
			pagination : true,
			pageSize : 20,
			pageList : [  10, 20, 30, 40, 50 ],
			border : true,
			fit : true,
			fitColumns : true,
			idField : 'cid',
			sortName : 'cmodifydate',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : true,
			columns : [ [ {
				title : 'id',
				field : 'cid',
				align : "center",
				width : 100,
				checkbox : true
			}, {
				title : '所属单位',
				field : 'deptname',
				align : "center",
				width : 160
			}, {
				title : '业务种类',
				field : 'kindname',
				align : "center",
				width : 120
			}, {
				title : '金额',
				field : 'cje',
				align : "center",
				width : 100
			},{
				title : '折算积分',
				field : 'cjf',
				align : "center",
				width : 100
			},
			{
				title : '创建日期',
				field : 'ccreatedate',
				align : "center",
				width : 100
			},
			{
				title : '修改日期',
				field : 'cmodifydate',
				align : "center",
				width : 100
			},
			{
				field : 'action',
				title : '操作',
				width : 100,
				align : 'center',
				formatter : function(value, row, index) {
					var str='';
                	<%if (authUtil.isAuth("/jfszAction!jfszEdit.action")){%>
                	str += sy.fs('<img onclick="jfszEdit(\'{0}\');" src="{1}" style="cursor: pointer;" title="修改"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/pencil.png');
                	<%}%>
                	<%if (authUtil.isAuth("/jfszAction!delete.action")){%>
                	str += sy.fs('<img onclick="jfszDelete(\'{0}\');" src="{1}" style="cursor: pointer;" title="删除"/>&nbsp;',row.cid,'${pageContext.request.contextPath}/css/themes/icons/no.png');
                	<%}%>
                	return str;
				}
			} ] ],
			toolbar : '#jfsz_toolbar'
		});
	});
	
	function jfszEdit(cid) {
		if (cid != undefined) {
			$('#jfsz_manager_datagrid').datagrid('unselectAll');
			$('#jfsz_manager_datagrid').datagrid('selectRecord', cid);
		}
		var rows = $('#jfsz_manager_datagrid').datagrid('getSelected');
		var p = parent.sy.dialog({
			title : '修改积分规则',
			iconCls : 'icon-edit',
			href : '${pageContext.request.contextPath}/jfszAction!jfszEdit.action',
			width : 520,
			height : 240,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/jfszAction!edit.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								jfsz_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ],
			onLoad : function() {
				var f = p.find('form');
				f.form('load', rows);
			}
		});
	};
	function jfszAppend() {
		var p = parent.sy.dialog({
			title : '添加营销积分规则',
			iconCls : 'icon-append',
			href : '${pageContext.request.contextPath}/jfszAction!jfszAdd.action',
			width : 520,
			height : 240,
			buttons : [ {
				text : '保存',
				iconCls : 'icon-save',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : '${pageContext.request.contextPath}/jfszAction!add.action',
						success : function(d) {
							var json = $.parseJSON(d);
							if (json.success) {
								jfsz_datagrid.datagrid('reload');
								p.dialog('close');
							}
							parent.sy.messagerShow({
								msg : json.msg,
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	function jfszRemove() {
		var rows = jfsz_datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '是否删除当前所选记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].cid);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/jfszAction!delete.action',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							jfsz_datagrid.datagrid('load');
							$('#jfsz_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
							parent.sy.messagerShow({
								title : '提示',
								msg : d.msg
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请选择要删除的记录！', 'error');
		}
	};

	function jfszDelete(cid) {
		$('#jfsz_manager_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
		$('#jfsz_manager_datagrid').datagrid('checkRow', $('#jfsz_manager_datagrid').datagrid('getRowIndex', cid));
		jfszRemove();
	}
</script>




<table id="jfsz_manager_datagrid"></table>
<div id="jfsz_toolbar" style="display: none;" >
<table  class="toolbar" >
	<tr>
		<my:per url="/jfszAction!jfszAdd.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-append',plain:true" onclick="jfszAppend();">新增</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
		<my:per url="/jfszAction!delete.action">
		<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-delete',plain:true" onclick="jfszRemove()">批量删除</a></td>
		<td><div class="datagrid-btn-separator"></div></td>
		</my:per>
	</tr>
</table>
</div>
